package com.samples.program;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import oracle.jdbc.pool.OracleDataSource;

import com.samples.util.ConfigurationManager;

public class Driver {

	public static OracleDataSource dataSource;

	static {
		try {
			dataSource = new OracleDataSource();
			dataSource.setDriverType(ConfigurationManager.getValue("driver_type"));
			dataSource.setServerName(ConfigurationManager.getValue("server_name"));
			dataSource.setPortNumber(Integer.parseInt(ConfigurationManager.getValue("port_number")));
			dataSource.setDatabaseName(ConfigurationManager.getValue("database_name"));
			dataSource.setUser(ConfigurationManager.getValue("user_name"));
			dataSource.setPassword(ConfigurationManager.getValue("password"));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
		Connection connection = dataSource.getConnection();
		Statement statement = connection.createStatement();
		ResultSet resultSet = statement.executeQuery("SELECT * FROM EMPLOYEES");
		while (resultSet.next()) {
			String firstName = resultSet.getString("FIRST_NAME");
			String lastName = resultSet.getString("LAST_NAME");
			System.out.println(firstName + " " + lastName);
		}
	}
}
